

public class ThreadTest {

    /**
     * 主方法
     * @param args
     */
    public static void main(String[] args) {

        //继承Thread
        myThread myThread1=new myThread();
        myThread1.setName("thread1_");
        myThread1.start();//启动线程

        myThread myThread2=new myThread();
        myThread2.setName("thread2_");
        myThread2.start();//启动线程

        //实现runnable接口，创建一个线程类即可，多个线程之间可以共享
        myRunnable myRunnable=new myRunnable();

        Thread thread1=new Thread(myRunnable);
        thread1.setName("runnable1_");
        thread1.start();//启动线程

        Thread thread2=new Thread(myRunnable);
        thread2.setName("runnable2_");
        thread2.start();//启动线程
        System.out.println(Thread.currentThread().getName()+"_"+System.currentTimeMillis());
    }

    /**
     * 创建Runnable
     *
     */
   public static class myRunnable implements Runnable{

        @Override
        public void run() {
         System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
        }
    }

    /**
     * 创建thread
     */
    public static class myThread extends Thread{
        @Override
        public void run() {
         System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
        }
    }
}
